package com.neuedu.service.impl;

import com.neuedu.dao.FangChanDao;
import com.neuedu.dao.impl.FangChanDaoImpl;
import com.neuedu.model.DongShu;
import com.neuedu.model.FangChan;
import com.neuedu.model.XiaoQu;
import com.neuedu.service.FangChanService;
import com.neuedu.vo.PageVO;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class FangChanServiceImpl implements FangChanService {
    FangChanDao fangChanDao=new FangChanDaoImpl();
    @Override
    public PageVO<FangChan> selectOnePage(Integer pageNo, Integer pageSize, String startTime, String endTime, String name) {
        Integer limitParams1=(pageNo-1)*pageSize;
        Integer limitParams2=pageSize;
        List<FangChan> fangChans = fangChanDao.selectPageList(limitParams1, limitParams2, startTime, endTime, name);
        int count = fangChanDao.selectCount(startTime, endTime, name);

        PageVO<FangChan> pageVO=new PageVO<>();
        pageVO.setCount(count);
        pageVO.setData(fangChans);
        pageVO.setPageNo(pageNo);
        pageVO.setPageSize(pageSize);
        pageVO.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        return pageVO;
    }
    public static int number=1;
    @Override
    public int add(FangChan fangChan) {
        //JC20240319001
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        String format = simpleDateFormat.format(date);
        String bianhao="HM"+format;
        if(number<10){
            bianhao=bianhao+"00"+number;
        }else if(number<100){
            bianhao=bianhao+"0"+number;
        }else{
            bianhao=bianhao+number;
        }
        fangChan.setFangchanbianma(bianhao);
        SimpleDateFormat chuangjianshijianSdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String chuangjianshijian=chuangjianshijianSdf.format(date);
        fangChan.setRuzhushijian(chuangjianshijian);

        return fangChanDao.add(fangChan);
    }

    @Override
    public FangChan findFangChanById(Integer id) {
        return fangChanDao.selectFangChanOne(id);
    }

    @Override
    public int editFangChanInfo(FangChan fangChan) {
        return fangChanDao.updateFangChan(fangChan);
    }

    @Override
    public int del(Integer[] ids) {
        return fangChanDao.del(ids);
    }

    @Override
    public List<FangChan> findFangChanByXiaoquName(String name) {
        List<FangChan> fangChans = fangChanDao.selectFangChanByXiaoQuName(name);
        return fangChans;
    }


}
